package com.hz.house.controller;

import com.hz.house.bean.vo.LoginCondition;
import com.hz.house.bean.vo.WxUserInfoBean;
import com.hz.house.common.ResultBean;
import com.hz.house.common.ResultUtil;
import com.hz.house.service.CustomerService;
import com.hz.house.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p> 用户相关接口
 * @author lfw
 */
@RestController
@RequestMapping("/api/v2/us")
@Api(value = "用户相关接口")
public class CustomerController {

	@Autowired
	private CustomerService customerService;

	/**
	* <p> 用户通过微信登陆小程序
	* @return
	*/
	@ApiOperation(value="用户登陆，code=小程序获取的jscode,invitorId=邀请者的id，非必填,sceneId=场景ID，后台定义，非必填")
	@PostMapping("/login")
	public Object userLogin(@RequestBody LoginCondition condition) {
		return this.customerService.userLoin(condition);
	}

	@ApiOperation("获取创建调用jsapi时所需要的签名")
	@GetMapping("/getJsApiSignature")
	public ResultBean getJsApiSignature(String url){
		return customerService.getJsApiSignature(url);
	}

	/**
	 *  <p>通过用户授权获取用户的基本信息，unionid等
	 * @param userInfo
	 * @return
	 */
	@ApiOperation(value = "用户授权后获取用户的基本信息和解密获取unionid")
	@PostMapping("/addUserInfo")
	public Object addUserInfo(@RequestBody WxUserInfoBean userInfo) {
		return this.customerService.addUserInfo(userInfo,CurrentUser.getCurrentUserId());
	}
	
	
	/**
	 *<p> 用户点击知道了后调用接口关闭后续显示 
	 */
	@ApiOperation(value = "首页提示收藏关闭接口")
	@GetMapping("/iKnow")
	public Object closeHomePageTip() {
		return this.customerService.closeHomePageTip(CurrentUser.getCurrentUserId());
	}

	@PostMapping("updateHeadImg")
	@ApiOperation(value = "更新用户头像")
	public ResultBean updateHeadImg(String headImg) {
		if(StringUtils.isEmpty(headImg)){
			return ResultUtil.fail("头像不能为空");
		}
		return customerService.updateHeadImg(headImg, CurrentUser.getCurrentUserId());
	}

}
